package ch.bfh.abcmmh.view.main.simulationparameterframe.subpanels;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.GridLayout;
import java.util.Hashtable;

import javax.swing.BorderFactory;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JSlider;

import ch.bfh.abcmmh.controller.operating.vehiclepool.VehiclePool;
import ch.bfh.abcmmh.view.GUIController;
import ch.bfh.abcmmh.view.main.simulationparameterframe.subpanels.sliderlistener.MayBeSliderListener;

public class MayBeParameterPanel extends JPanel {

	private static final long serialVersionUID = 1L;

	private VehiclePool vehiclePool;
	private JSlider carmbSlider, btmbSlider;

	public MayBeParameterPanel(GUIController guiController) {
		this.vehiclePool = guiController.getLogicController().getVehiclePool();
		setLayout(new GridLayout(2, 1));

		carmbSlider = setupMaybeSlider();
		btmbSlider = setupMaybeSlider();
		carmbSlider.setValue((int) (vehiclePool.getCmb()*10));
		btmbSlider.setValue((int) (vehiclePool.getBtmb()*10));
		carmbSlider.addChangeListener(new MayBeSliderListener(this, vehiclePool));
		btmbSlider.addChangeListener(new MayBeSliderListener(this, vehiclePool));
		
		add(new MayBeSlider(carmbSlider,"Possibility for dawdle by cars"));
		add(new MayBeSlider(btmbSlider,"Possibility for dawdle by busses or trucks"));

	}

	private class MayBeSlider extends JPanel {

		private static final long serialVersionUID = 1L;

		private MayBeSlider(JSlider slider, String text) {
			setLayout(new BorderLayout());
			setBorder(BorderFactory.createLineBorder(Color.BLACK));

			this.add(new JLabel(text), BorderLayout.NORTH);
			this.add(slider, BorderLayout.SOUTH);
		}
	}


	private JSlider setupMaybeSlider() {
		JSlider slider = new JSlider();
		slider.setMinimum(0);
		slider.setMaximum(10);
		slider.setMinorTickSpacing(1);
		slider.setMajorTickSpacing(2);
		slider.setSnapToTicks(true);
		slider.setPaintTicks(true);
		Hashtable<Integer, JLabel> dict = new Hashtable<Integer, JLabel>();
		dict.put(0, new JLabel(" never"));
		dict.put(10, new JLabel("allways  "));
		slider.setLabelTable(dict);
		slider.setPaintLabels(true);

		return slider;
	}


	public JSlider getCarmbSlider() {
		return carmbSlider;
	}


	public JSlider getBtmbSlider() {
		return btmbSlider;
	}
	
	
}
